home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 September / Chip_2000-09_cd1.bin / sharewar / Slunec / app / 16 / ARCHIVES.SWG / 0011_RAR EXPLANATION.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-03  |  7KB  |  269 lines

  1. --------A-RAR-------------------------------
  2.  
  3.    Archive  file consists of variable length  blocks. The order of these
  4. blocks may vary, but the first block must be marker block followed by an
  5. archive header block.
  6.  
  7.    Each block begins with following fields:
  8.  
  9. HEAD_CRC       2 bytes     CRC of total block or block part
  10. HEAD_TYPE      1 byte      Block type
  11. HEAD_FLAGS     2 bytes     Block flags
  12. HEAD_SIZE      2 bytes     Block size
  13. ADD_SIZE       4 bytes     Optional field - added block size
  14.  
  15.    Field ADD_SIZE present only if (HEAD_FLAGS & 0x8000) != 0
  16.  
  17.    Total block size is HEAD_SIZE if (HEAD_FLAGS & 0x8000) == 0
  18. and HEAD_SIZE+ADD_SIZE if the field ADD_SIZE is present - when
  19. (HEAD_FLAGS & 0x8000) != 0.
  20.  
  21.    In each block the followings bits in HEAD_FLAGS have the same meaning:
  22.  
  23.   0x4000 - if set, older RAR versions will ignore the block
  24.            and remove it when the archive is updated.
  25.            if clear, the block is copied to the new archive
  26.            file when the archive is updated;
  27.  
  28.   0x8000 - if set, ADD_SIZE field is present and the full block
  29.            size is HEAD_SIZE+ADD_SIZE.
  30.  
  31.   Declared block types:
  32.  
  33. HEAD_TYPE=0x72          marker block
  34. HEAD_TYPE=0x73          archive header
  35. HEAD_TYPE=0x74          file header
  36. HEAD_TYPE=0x75          comment header
  37. HEAD_TYPE=0x76          extra information
  38.  
  39.    Comment  block is actually used only within other blocks and does not
  40. exist separately.
  41.  
  42.    Archive processing is made in the following manner:
  43.  
  44. 1. Read and check marker block
  45. 2. Read archive header
  46. 3. Read or skip HEAD_SIZE-sizeof(MAIN_HEAD) bytes
  47. 4. If end of archive encountered then terminate archive processing,
  48.    else read 7 bytes into fields HEAD_CRC, HEAD_TYPE, HEAD_FLAGS,
  49.    HEAD_SIZE.
  50. 5. Check HEAD_TYPE.
  51.    In case block read needed:
  52.          if HEAD_TYPE==0x74
  53.            read file header ( first 7 bytes already read )
  54.            read or skip HEAD_SIZE-sizeof(FILE_HEAD) bytes
  55.            read or skip FILE_SIZE bytes
  56.          else
  57.            read corresponding HEAD_TYPE block:
  58.              read HEAD_SIZE-7 bytes
  59.              if (HEAD_FLAGS & 0x8000)
  60.                read ADD_SIZE bytes
  61.    In case block skip needed:
  62.          skip HEAD_SIZE-7 bytes
  63.          if (HEAD_FLAGS & 0x8000)
  64.            skip ADD_SIZE bytes
  65. 6. go to 4.
  66.  
  67.  
  68.  ╔════════════════════════════════════════════════════════════════════════╗
  69.  ║▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒  Block Formats  ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒║
  70.  ╚════════════════════════════════════════════════════════════════════════╝
  71.  
  72.  
  73.    Marker block ( MARK_HEAD )
  74.  
  75.  
  76. HEAD_CRC        Always 0x6152
  77. 2 bytes
  78.  
  79. HEAD_TYPE       Header type: 0x72
  80. 1 byte
  81.  
  82. HEAD_FLAGS      Always 0x1a21
  83. 2 bytes
  84.  
  85. HEAD_SIZE       Block size = 0x0007
  86. 2 bytes
  87.  
  88.    The  marker  block is actually considered  as  a fixed byte sequence:
  89. 0x52 0x61 0x72 0x21 0x1a 0x07 0x00
  90.  
  91.  Archive header ( MAIN_HEAD )
  92.  
  93. HEAD_CRC        CRC of fields HEAD_TYPE to RESERVED2
  94. 2 bytes
  95.  
  96. HEAD_TYPE       Header type: 0x73
  97. 1 byte
  98.  
  99. HEAD_FLAGS      Bit flags:
  100. 2 bytes
  101.                 0x01    - Volume attribute (archive volume)
  102.                 0x02    - Archive comment present
  103.                 0x04    - Archive lock attribute
  104.                 0x08    - Solid attribute (solid archive)
  105.                 0x10    - Unused
  106.                 0x20    - Authenticity information present
  107.  
  108.                 other bits in HEAD_FLAGS are reserved for
  109.                 internal use
  110.  
  111. HEAD_SIZE       Archive header total size including archive
  112. 2 bytes         comments and other added fields
  113.  
  114. RESERVED1       Reserved
  115. 2 bytes
  116.  
  117. RESERVED2       Reserved
  118. 4 bytes
  119.  
  120.  
  121. Comment block   present if (HEAD_FLAGS & 0x02) != 0
  122.  
  123.  
  124. ????            Other included blocks - reserved for
  125.                 future use
  126.  
  127.  
  128.  
  129.    File header (File in archive)
  130.  
  131.  
  132. HEAD_CRC        CRC of fields from HEAD_TYPE to FILEATTR
  133. 2 bytes         and file name
  134.  
  135. HEAD_TYPE       Header type: 0x74
  136. 1 byte
  137.  
  138. HEAD_FLAGS      Bit flags:
  139. 2 bytes
  140.                 0x01 - file continued from previous volume
  141.                 0x02 - file continued in next volume
  142.                 0x04 - file encrypted with password
  143.                 0x08 - file comment present
  144.  
  145.                 (HEAD_FLAGS & 0x8000) == 1, because full
  146.                 block size is HEAD_SIZE + PACK_SIZE
  147.  
  148. HEAD_SIZE       File header full size including file name,
  149. 2 bytes         comments and other added fields
  150.  
  151. PACK_SIZE       Compressed file size
  152. 4 bytes
  153.  
  154. UNP_SIZE        Uncompressed file size
  155. 4 bytes
  156.  
  157. HOST_OS         Operating system used for archiving
  158. 1 byte          (value 0 stands for MS DOS)
  159.  
  160. FILE_CRC        File CRC
  161. 4 bytes
  162.  
  163. FTIME           Date and time in standard MS DOS format
  164. 4 bytes
  165.  
  166. UNP_VER         RAR version needed to extract file
  167. 1 byte
  168.  
  169. METHOD          Packing method
  170. 1 byte
  171.  
  172. NAME_SIZE       File name size
  173. 2 bytes
  174.  
  175. ATTR            File attributes
  176. 4 bytes
  177.  
  178. FILE_NAME       File name - string of NAME_LEN bytes size
  179.  
  180.  
  181. Comment block   present if (HEAD_FLAGS & 0x08) != 0
  182.  
  183.  
  184. ????            Other extra included blocks - reserved for
  185.                 future use
  186.  
  187.  
  188.  
  189.   Comment block
  190.  
  191.  
  192. HEAD_CRC        CRC of fields from HEAD_TYPE to COMM_CRC
  193. 2 bytes
  194.  
  195. HEAD_TYPE       Header type: 0x75
  196. 1 byte
  197.  
  198. HEAD_FLAGS      Bit flags
  199. 2 bytes
  200.  
  201. HEAD_SIZE       Comment header size + comment size
  202. 2 bytes
  203.  
  204. UNP_SIZE        Uncompressed comment size
  205. 2 bytes
  206.  
  207. UNP_VER         RAR version needed to extract comment
  208. 1 byte
  209.  
  210. METHOD          Packing method
  211. 1 byte
  212.  
  213. COMM_CRC        Comment CRC
  214. 2 bytes
  215.  
  216. COMMENT         Comment text
  217.  
  218.  
  219.  
  220.   Extra info block
  221.  
  222.  
  223. HEAD_CRC        Block CRC
  224. 2 bytes
  225.  
  226. HEAD_TYPE       Header type: 0x76
  227. 1 byte
  228.  
  229. HEAD_FLAGS      Bit flags
  230. 2 bytes
  231.  
  232. HEAD_SIZE       Total block size
  233. 2 bytes
  234.  
  235. INFO            Other data
  236.  
  237.  
  238.  ╔════════════════════════════════════════════════════════════════════════╗
  239.  ║▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒  Application notes  ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒║
  240.  ╚════════════════════════════════════════════════════════════════════════╝
  241.  
  242.    1. Should fields and included blocks be added in the future, their
  243. size would be included in HEAD_SIZE.
  244.  
  245.    2. To process SFX archive you need to skip the SFX module searching
  246. marker block in the archive. There is no marker block sequence (0x52 0x61
  247. 0x72 0x21 0x1a 0x07 0x00) in the SFX module itself.
  248.  
  249.    3. The CRC is calculated using the standard polynomial 0xEDB88320. In
  250. case the size of the CRC is less than 4 bytes, only the low order bytes
  251. are used.
  252.  
  253.    4. Packing method encoding:
  254.          0x30 - storing
  255.          0x31 - fastest compression
  256.          0x32 - fast compression
  257.          0x33 - normal compression
  258.          0x34 - good compression
  259.          0x35 - best compression
  260.  
  261.    5. The RAR extraction version number is encoded as 10 * Major version
  262. + minor version.
  263.  
  264. EXTENSION:RAR
  265. OCCURENCES:PC
  266. PROGRAMS:RAR.EXE
  267. SEE ALSO:ZIP,ARJ
  268.  
  269.